<?php

namespace App\Admin\Actions\Auction;

use App\Library\Logic\OperateLogLogic;
use App\Models\AuctionModel;
use Illuminate\Http\Request;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Actions\Response;
use Encore\Admin\Actions\RowAction;

class AuctionSmsMessageSwitchAction extends RowAction
{
    public function __construct(int $status = 0)
    {
        parent::__construct();
        $this->name = $status ? '关闭短信推送' : '开启短信推送';
    }

    public function handle(AuctionModel $model, Request $request): Response
    {
        $power = (int)$model->push_switch ? 0 : 1;
        $model->push_switch = $power;
        $model->save();
        OperateLogLogic::add(Admin::user()->user_id, 'admin.auction.SmsMessageSwitch', ['pushSwitch' => $power]);
        return $this->response()->success('操作成功')->refresh();
    }
}
